/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.ban.news.server.check.checkers;

import cn.ac.iie.di.ban.news.server.check.CheckResult;
import cn.ac.iie.di.ban.news.server.check.Checker;
import java.text.SimpleDateFormat;

/**
 *
 * @author zwlin
 */
public class TimeLaterChecker implements Checker<String, String> {

    private static SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");

    /**
     *
     * @param src bigger
     * @param target smaller
     * @return
     */
    @Override
    public CheckResult check(String src, String target) {
        try {
            if (null == src || (src = src.trim()).isEmpty()) {
                return new CheckResult();
            }
            formatter.parse(src);
        } catch (Exception ex) {
            return new CheckResult("time format error.");
        }
        return src.compareTo(target) < 0
                ? new CheckResult("time too small than needed.")
                : new CheckResult();
    }

}
